package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.SOrderImportedFeedetailService;
import cn.huiyunche.base.service.mappers.SOrderImportedFeedetailMapper;
import cn.huiyunche.base.service.model.SOrderImportedFeedetail;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class SOrderImportedFeedetailServiceImpl implements SOrderImportedFeedetailService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SOrderFeeDetailServiceImpl.class);

    @Autowired
    private SOrderImportedFeedetailMapper sOrderImportedFeedetailMapper;

    @Override
    public long addFeeDetail(long importOrderId, long feeTypeId, String feeName, BigDecimal price, BigDecimal actualAmount) {
        LOGGER.info("addFeeDetail params : {}，{}，{}", importOrderId, feeTypeId, price);
        if (0 == importOrderId) {
            LOGGER.error("addFeeDetail importOrderId must not be 0");
            throw new BusinessException("订单id不能为0！");
        }
        if (0 == feeTypeId) {
            LOGGER.error("addFeeDetail feeTypeId must not be 0");
            throw new BusinessException("订单类型id不能为0");
        }
        if (null == price) {
            LOGGER.error("addFeeDetail price must not be null");
            throw new BusinessException("金额不能为空！");
        }
        SOrderImportedFeedetail feedetail = new SOrderImportedFeedetail();
        feedetail.setImportedOrderId(importOrderId);
        feedetail.setFeeTypeId(feeTypeId);
        feedetail.setFeeName(feeName);
        feedetail.setMoney(price);
        feedetail.setActualAmount(actualAmount);
        sOrderImportedFeedetailMapper.insertSelective(feedetail);
        return feedetail.getId();
    }

}
